home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: lewkbj@ix.netcom.com (leonel wizel )
- Newsgroups: comp.lang.c++
- Subject: help with homework
- Date: 17 Apr 1996 02:13:06 GMT
- Organization: Netcom
- Message-ID: <4l1k3i$kle@dfw-ixnews2.ix.netcom.com>
- NNTP-Posting-Host: ix-nyc23-13.ix.netcom.com
- X-NETCOM-Date: Tue Apr 16 9:13:06 PM CDT 1996
-
-
- Please I need help to complete this file: this file suppose to
- increment the object time by one second to the next hour, to the
- next minute to the next day:
-
- I need some help please:
-
-
- the program suppose to modify to include a tick member function
- that increments the time stored in the Time object by one second. The
- time object should always remain in a consistent state. The driver
- program that tests the tick member function in a loop that prints the
- time in standard format during each iteration of the loop to illustrate
- that the tick member functions workds correctly.
-
- Incrementing into the next minute.
- Incrementing into the next hour.
- incrementing into the next day(i.e., 11:59:59 PM to 12:00:00 AM).
-
-
- //TIME3.H
-
- #ifndef TIME3_H
- #define TIME3_H
-
-
- class Time {
- public:
- Time(int = 0, int = 0, int = 0); // constructor
-
- //set functions
-
- void setTime(int, int, int); //set hour, minute, second
- void setHour(int); //set hour
- void setMinute(int); //set minute
- void setSecond(int); //set second
-
- //get functions
-
- int getHour(); //return hour
- int getMinute(); //return minute
- int getSecond(); //return second
-
- void tick_increment();
- void printMilitary(); //output military time
- void printStandard(); //output standard time
-
- private:
- int hour; //0 - 23
- int minute; //0 - 59
- int second; //0 - 59
- };
-
-
- #endif
-
-
- #include "time3.h"
- #include <iostream.h>
-
-
- //constructor function
-
- Time::Time(int hr, int min, int sec) {setTime (hr, min, sec); }
-
- void Time::setTime( int h, int m, int s)
- {
- hour = (h >= 0 && h < 24) ? h : 0;
- minute = (m >= 0 && m < 60) ? m : 0;
- second = (s >= 0 && s < 60) ? s : 0;
- }
-
- void Time::setHour(int h) { hour = (h >= 0 && h < 24) ? h : 0;}
-
- void Time::setMinute(int m)
- { minute = (m >= 60) ? m : 0; }
-
- void Time::setSecond(int s)
- { second = (s >= 60) ? s : 0; }
-
-
- int Time::getHour() {return hour; }
-
- int Time::getMinute() {return minute; }
-
- int Time::getSecond() {return second; }
-
-
- void Time::tick_increment()
- {
- if(second == 60)
- {
- second = 0;
- minute++;
- }
- second++;
- if (second == 60)
- {
- second = 0;
- minute++;
- }
- if(minute == 60)
- {
- minute = 0;
- hour++;
- }
- if (hour == 24)
- {
- hour %= 24;
- }
- }
- void Time::printMilitary()
- {
- cout << (hour < 10 ? "0" : "") << hour << ":"
- << (minute < 10 ? "0" : "") << minute << ":"
- << (second < 10 ? "0" : "") << second;
- }
-
- void Time::printStandard()
- {
- cout << ((hour == 0 || hour == 12) ? 12 : hour %12) << ":"
- << (minute < 10 ? "0" : "") << minute << ":"
- << (second < 10 ? "0" : "") << second
- << (hour < 12 ? " AM" : " PM");
- }
-
- #include <iostream.h>
- #include "time3.h"
- #include "time3.cpp"
-
-
- main()
- {
- Time t;
-
- t.setTime(23, 59, 59);
-
- for(long int i = 1; i <= 2; i++)
- {
- cout << endl << endl;
- cout << " Hour " << t.getHour()
- << " Minute " << t.getMinute()
- << " Second " << t.getSecond();
-
- cout <<"the initial time before incrementing is: " << endl
- << endl;
-
- t.printStandard();
- cout << endl;
- t.printMilitary();
-
- t.tick_increment();
- cout << " Hour " << t.getHour()
- << " Minute " << t.getMinute()
- << " Second " << t.getSecond()
- <<" the time after incrementing is: " << endl;
-
- t.printStandard();
- cout << endl;
- t.printMilitary();
-
- }
-
-
-
- return 0;
- }
-
-
-
-
-
-
-
-